package com.bipa.dao;

import com.bipa.bean.Article;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ArticleDao {

    @Select("SELECT * FROM ec_article  where type_code like CONCAT('%',#{typeCode} ,'%') and title like CONCAT('%',#{keyword},'%') and disabled = '0' limit #{startSize},#{pageSize}")
    public List<Article> findArticles(@Param("typeCode") String typeCode, @Param("keyword") String keyword,@Param("startSize")Integer startSize,@Param("pageSize")Integer pageSize);

    @Select("SELECT * FROM ec_article  where type_code like CONCAT('%',#{typeCode} ,'%') and title like CONCAT('%',#{keyword},'%') limit #{startSize},#{pageSize}")
    public List<Article> findArticles1(@Param("typeCode") String typeCode, @Param("keyword") String keyword,@Param("startSize")Integer startSize,@Param("pageSize")Integer pageSize);

    @Select("SELECT * FROM ec_article  where type_code like CONCAT('%',#{typeCode} ,'%') and title like CONCAT('%',#{keyword},'%') and disabled = '0'")
    public List<Article> findAll(@Param("typeCode") String typeCode, @Param("keyword") String keyword);

    @Select("SELECT * FROM ec_article  where id = #{id}")
    public Article getArticleById(@Param("id") Integer id);

    @Update("update ec_article set disabled = #{disabled} where id = #{id}")
    public void removeOrPutArticle(@Param("id")Integer id,@Param("disabled")Integer disabled);

    @Update("update ec_article set type_code = #{type_code},title= #{title},discount= #{discount},locality=#{locality},price=#{price},storage=#{storage}, image = #{image} ,description=#{description},supplier=#{supplier} where id = #{id}")
    public void update(Article article);

    @Insert("insert into ec_article(title, supplier, price, locality,storage, image, description, type_code, create_date)  values(#{title},supplier=#{supplier},#{price}, #{locality},#{storage}, #{image},#{description}, #{type_code}, #{create_date})")
    public void insert(Article article);
}
